package com.blb.community.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.community.Annotation.Log;
import com.blb.community.entity.ZyComment;
import com.blb.community.entity.ZyCommunityInteraction;
import com.blb.community.entity.vo.CommunityInteractionVO;
import com.blb.community.entity.vo.ZyCommunityInteractionVo;
import com.blb.community.service.IZyCommentService;
import com.blb.community.service.IZyCommunityInteractionService;
import com.blb.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 社区互动表 前端控制器
 * </p>
 *
 * @author 帅帅
 * @since 2022-07-02
 */
@RestController
@RequestMapping("/zy-community-interaction")
@CrossOrigin
@Api(tags = "社区互动")
public class ZyCommunityInteractionController {

    @Autowired
    private IZyCommunityInteractionService communityInteractionService;

    @Autowired
    private IZyCommunityInteractionService iZyCommunityInteractionService;

    @Autowired
    private IZyCommentService iZyCommentService;

    @GetMapping("/commentPage")
    @ApiOperation("帖子分页显示")
    public ResponseResult< IPage<ZyCommunityInteractionVo>> getAllCommentsPage(Long current){
        IPage<ZyCommunityInteractionVo> allCommentsPage = iZyCommunityInteractionService.getAllCommentsPage(current, 5L);
        return ResponseResult.ok(allCommentsPage);
    }

    @GetMapping("/commentsAll")
    @ApiOperation("显示所有帖子/查看所有")
    public ResponseResult<List<ZyCommunityInteractionVo>> getAllCommentsPage(){
        List<ZyCommunityInteractionVo> allComments = iZyCommunityInteractionService.getAllComments();
        return ResponseResult.ok(allComments);
    }


    @Log(module = "发布帖子", operationType = 1, requestMethod = "POST")
    @PostMapping("/add")
    @ApiOperation("发布帖子")
    public ResponseResult<String> addCommentsInteraction(ZyCommunityInteraction zyCommunityInteraction){
        boolean save = iZyCommunityInteractionService.save(zyCommunityInteraction);
        return ResponseResult.ok("add");
    }

    @Log(module = "发表评论", operationType = 1, requestMethod = "POST")
    @PostMapping("/addcomments")
    @ApiOperation("发表评论")
    public ResponseResult<String> addComments(ZyComment zyComment){
       iZyCommentService.save(zyComment);
       return ResponseResult.ok("add");
    }

    @ApiOperation("小区互动模糊")
    @PostMapping("/interactions/page")
    public ResponseResult<IPage<CommunityInteractionVO>> getInteractionPage(CommunityInteractionVO communityInteractionVO){
        Page<CommunityInteractionVO> page = new Page<>(communityInteractionVO.getCurrent(), 5L);
        IPage<CommunityInteractionVO> interactionPage = communityInteractionService.getInteractionPage(communityInteractionVO, page);
        return ResponseResult.ok(interactionPage);

    }


    @Log(module = "小区互动删除", operationType = 3, requestMethod = "DELETE")
    @ApiOperation("小区互动删除")
    @DeleteMapping("/interaction/{id}")
    public ResponseResult<String> delInteraction(@PathVariable Long id){
        communityInteractionService.delInteraction(id);
        return ResponseResult.ok("删除成功");
    }
}
